package com.liugui.basicsgrammar2;

/**
 * @ClassName: SumOfEven
 * @Author: liugui
 * @Date: 2020-10-18 13:38
 **/
public class SumOfEven {
    public static void main(String[] args) {

        System.out.println( 4 % 2 );
        int i = whileMethod();
        System.out.println("i:" + i); //250500
        int l = doWhileMethod();
        System.out.println("l:" + l); //250500
    }

    //实现计算 1-1000 中所有偶数的和，并输出。
    private static  Integer whileMethod(){
        int i = 1000;
        int num = 0;
        while (i >= 1){
            if (0 == i  % 2 ){
                num += i;
            }
            i = -- i ;
        }
        return num;
    }

    private static  Integer doWhileMethod(){
        int i = 1000; //循环1000次
        int num = 0;
        do {
            if (0 == i  % 2 ){ //取偶数
                num += i; //偶数相加
            }
            i = -- i; //循环次数减一
        }while (i >= 1);  //到1结束循环
        return num;
    }
}
